﻿
function puttheinfos() {


    $.ajax({
        url: "/Infos/PutBasicInfos",
        type: "post",
        async: false,
        data: $("#formBasicInfo").serialize(),
        success: function (datas) {


            $("#infosSave").attr("disabled", true);
            document.getElementById("infosSave").innerHTML = "已经完成保存，请勿重复提交";
            lis = datas;
            console.log(lis);
            globalparams = datas;
            layui.use('layer', function () {
                layer = layui.layer;
                layer.msg('该数据完成提交', { icon: 1 }
                );
            });
            var form = layui.form;
            //$("#jbxxid").val() = datas;
            form.val('formBasicInfo', {
                "jbxxid": datas

            });



        }
    })


}


function checktheid() {

    var idnumber = $("#idNumber").val();

    $.ajax({
        url: "/Infos/checktheidnumber?id=" + idnumber,
        type: "get",
        async: false,
        success: function (datas) {
            console.log(datas);

            if (datas == true) {

                /*layer.msg("有啦");*/
                $("#idnumbermention").show();
            }
            else {


                $("#idnumbermention").hide();

            }
        }
    })




}








$(document).ready(function () {

        
    $("#idNumber").blur(function () {

        checktheid();

    });

})


function puttheshengyuInfos() {

    if ($("#hyzk").val() == '') {


        layer.msg("请选择婚姻状况");
        return;

    }
    if ($("#shengyu").val() == '') {


        layer.msg("请选择生育情况");
        return;

    }
    if ($("#kidsnumber").val() == '') {


        layer.msg("请选择子女数量");
        return;

    }

    if (getParam("uuid") == null) { 

        //var _uuid = '161616-16161-16';
        var _uuid = $("#jbxxid").val();
        var a = $("#formofShengyu").serialize();
        var x = a + '&uuid=' + _uuid;


        $.ajax({
            url: "/Infos/PutHunyuInfos",
            type: "post",
            async: false,
            data: x,
            success: function (datas) {

                $("#kidssave").attr("disabled", true);
                document.getElementById("kidssave").innerHTML = "已经完成保存，请勿重复提交";

                lis = datas;
                console.log(lis);
                globalparams = datas;
                layui.use('layer', function () {
                    layer = layui.layer;
                    layer.msg('该数据完成提交', { icon: 1 }
                    );
                });





            }
        })
    }
    else {


        shengyumodify();



    }



}







function getthesitudation() {


    if (getParam("uuid") == null) {
        if ($("#jbxxid").val() == "") {


            layer.msg("请先完成基本信息的填报，然后再提交健康信息");
            return;
        }


        var _uuid = $("#jbxxid").val();
        var keke = $("#healthsituation").serialize();
        var x = keke + '&uuid=' + _uuid;
        $.ajax({
            url: "/Infos/PuttheSituation",
            type: "post",
            async: false,
            data: x,
            success: function (datas) {

                $("#healthSave").attr("disabled", true);
                document.getElementById("healthSave").innerHTML = "已经完成保存，请勿重复提交";


                lis = datas;
                console.log(lis);
                globalparams = datas;
                layui.use('layer', function () {
                    layer = layui.layer;
                    layer.msg('该数据完成提交', { icon: 1 }
                    );
                });





            }
        })
    }
    else {

        healthmodify();


    }



}



function putthegangweidata() {


 

    if ($("#worknumber").val() == '') {


        layer.msg("请填写工号");
        return;

    }
    if ($("#demo100").val() == '') {


        layer.msg("请填写部门");
        return;

    }
    if ($("#demo200").val() == '') {


        layer.msg("请填写流程部门");
        return;

    }

    if ($("#gangwei").val() == '') {


        layer.msg("请填写岗位");
        return;

    }
    if ($("#cengji").val() == '') {


        layer.msg("请填写层级信息");
        return;

    }

    if ($("#zhiji").val() == '') {


        layer.msg("请填写职级信息");
        return;

    }


    if ($("#datestartwork").val() == '') {


        layer.msg("请选择入司日期");
        return;

    }


    //console.log(getParam("uuid"));
    if (getParam("uuid") == null) { //新增条件判断


        if ($("#jbxxid").val() == '') {
            layer.msg("请填写完基本信息，再填部门的信息");
            return;
        }


    //if ($("#jbxxid").val() == '') {
        var _uuid = $("#jbxxid").val();
        console.log(_uuid);
        var form = layui.form;
        var kkid = form.val('formBasicInfo').jbxxid;
        console.log(kkid);

        var a = $("#formgangweiInfo").serialize();
        var b = $("#formgangweiInfo");

        var x = a + '&uuid=' + _uuid;


        $.ajax({
            url: "/Infos/PutGangweiInfos",
            type: "post",
            async: false,
            data: x,
            success: function (datas) {


                $("#gangweisave").attr("disabled", true);
                document.getElementById("gangweisave").innerHTML = "已经完成保存，请勿重复提交";
                lis = datas;
                console.log(lis);
                globalparams = datas;
                layui.use('layer', function () {
                    layer = layui.layer;
                    layer.msg('该数据完成提交', { icon: 1 }
                    );
                });





            }
        })
    } else {

        //修改逻辑

        gangweimodify();
    }




}






function puttheInfosdata() {




    if ($("#name").val() == '') {


        layer.msg("请填写名字");
        return;

    }
    if ($("#sexbox").val() == '') {



        layer.msg("请选择性别");
        return;

    }

    if ($("#age").val() == '') {

        layer.msg("请填写年龄");
        return;
    }
    if ($("#birthdate").val() == '') {

        layer.msg("请选择出生日期");
        return;
    }
    if ($("#bloodbox").val() == '') {

        layer.msg("请选择血型");
        return;
    }
    if ($("#nation").val() == '') {

        layer.msg("请选择民族");
        return;
    }
    if ($("#phonenumber").val() == '') {

        layer.msg("请填写手机号");
        return;
    }
    if ($("#idNumber").val() == '') {

        layer.msg("请填写身份证号码");
        return;
    }
    if ($("#sheng").val() == '') {

        layer.msg("请选择籍贯");
        return;
    }
    if ($("#xjsheng").val() == '') {

        layer.msg("请选择现居地");
        return;
    }
    if ($("#zhengzhimianmao").val() == '') {

        layer.msg("请选择政治面貌");
        return;
    }
    if ($("#dateOfJointhePartydate").val() == '') {

        layer.msg("请选择入党时间");
        return;
    }

    if ($("#hjszplace").val() == '') {



        layer.msg("请填写户籍详情");
        return;
    }
    if ($("#actuallyplace").val() == '') {



        layer.msg("请填写现居地详情");
        return;
    }

    console.log("_____________");
    if ($("#jbxxid").val() == '') {
        var idnum = $("#idNumber").val();

        $.ajax({
            url: "/Infos/checktheidnumber?id=" + idnum,
            type: "get",
            async: false,
            success: function (datas) {
                console.log(datas);

                if (datas == true) {

                    layer.confirm('这个人已经存在了，您确定要继续将这个人也保存？', {
                        btn: ['确定保存', '取消'] //按钮
                    }, function () {
                        puttheinfos();
                    }, function () {
                        //layer.msg('也可以这样', {
                        //    time: 20000, //20s后自动关闭
                        //    btn: ['明白了', '知道了']
                        //});
                    });

                    /*                $("#idnumbermention").show();*/
                }
                else {

                    puttheinfos();
                    //$("#idnumbermention").hide();

                }
            }
        })
    }
    else {


        infosmodify();

        //修改逻辑用UUID
    }

    //提交基本信息





}

//修改基本信息
function infosmodify() {
    console.log("成功调用修改");
    var a = $("#formBasicInfo").serialize();
    var _uuid = $("#jbxxid").val();
    var x = a + '&uuid=' + _uuid;
    $.ajax({
        url: "/Infos/ModifytheInfos",
        type: "post",
        data: x,
        async: false,
        success: function (datas) {
            layui.use('layer', function () {
                layer = layui.layer;
                layer.msg('该数据修改！', { icon: 1 }
                );
            });

        }
    })
    

}
function gangweimodify() {

    console.log("成功调用岗位修改");
    var a = $("#formgangweiInfo").serialize();
    var _uuid = $("#jbxxid").val();
    var x = a + '&uuid=' + _uuid;
    $.ajax({
        url: "/Infos/Modifythegangwei",
        type: "post",
        data: x,
        async: false,
        success: function (datas) {
            layui.use('layer', function () {
                layer = layui.layer;
                layer.msg('该数据完成修改！', { icon: 1 }
                );
            });

        }
    })

}


function shengyumodify() {


    console.log("成功调用生育修改");

    var a = $("#formofShengyu").serialize();
    var _uuid = $("#jbxxid").val();
    var x = a + '&uuid=' + _uuid;
    $.ajax({
        url: "/Infos/Modifytheshengyu",
        type: "post",
        data: x,
        async: false,
        success: function (datas) {
            layui.use('layer', function () {
                layer = layui.layer;
                layer.msg('该数据完成修改！', { icon: 1 }
                );
            });

        }
    })



}

function healthmodify() {

    console.log("成功调用健康修改");
    var a = $("#healthsituation").serialize();
    var _uuid = $("#jbxxid").val();
    var x = a + '&uuid=' + _uuid;
    $.ajax({
        url: "/Infos/ModifytheHealth",
        type: "post",
        data: x,
        async: false,
        success: function (datas) {
            layui.use('layer', function () {
                layer = layui.layer;
                layer.msg('该数据完成修改！', { icon: 1 }
                );
            });

        }
    })

}

function getParam(paramName) {
    paramValue = "", isFound = !1;
    if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
        arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0;
        while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
    }
    return paramValue == "" && (paramValue = null), paramValue
}



function diaoshen(jbxxid) {



    console.log("mmp");
    var corn;
    $.ajax({
        url: "/Infos/GettheCorn",
        type: "post",
        data: { "jbxxid": jbxxid },
        async: false,
        success: function (resut) {
            corn = resut;
        }
    });


    return corn;

}

function xuexichange() {



    console.log("xuexinchangfe");

}

layui.use(['form', 'util', 'laydate', 'element'], function () {

    var form = layui.form;
    var layer = layui.layer;
    var util = layui.util;
    var laydate = layui.laydate;
    var element = layui.element;

    form.on('select(jiangchengmodechose)', function (data) {


        console.log("modechose");
        //var message = $("select[name=jiangchengmode]").val();

        //if message 




    });



    form.on('button(newtake)', function (data) {

        console.log("提交啦！！！");
        layer.alert(JSON.stringify(data.field), {
            title: '最终的提交信息'
        })
        return false;
    });


    form.on('select(xiala)', function (data) {


        var message = $("select[name=notpassresult]").val();

        if (message == '其他原因') {
            console.log("show");
            $("#xuexinbeizhu").show();

        }
        else {

            $("#xuexinbeizhu").hide();

        }



    });




    form.on('select(resultxiala)', function (data) {

        var mess = $("select[name=xuexinresult]").val();

        if (mess == '未能查实') {

            $("#whynotpass").show();
            $("#xuexinupload").hide();
            $("#uploadthexuexin").hide();
            $("#xuexidiv").hide();
        }
        else {

            $("#whynotpass").hide();
            $("#xuexinupload").show();
            $("#xuexinbeizhu").hide();
            $("#uploadthexuexin").show();
            $("#xuexidiv").show();



        }


    } )







})



layui.use(['upload', 'table','element'], function () {
    upload = layui.upload;
    element = layui.element;
    var table = layui.table;
    var uploadListIns = upload.render({
        elem: '#xuexinupload'
        , elemList: $('#demoListxuexin') //列表元素对象
        , url: '/upload' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
        , accept: 'file'
        , multiple: true
        , number: 3
        , auto: false
        , bindAction: '#uploadthexuexin'
        , choose: function (obj) {
            var that = this;
            var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
            //读取本地文件

            console.log("完成文件的选择");
            obj.preview(function (index, file, result) {
                var tr = $(['<tr id="upload-' + index + '">'
                    , '<td><input style="border: 0;" readonly class="xuexinname" type="text" value="'
                    + file.name + '"/></td>'
                    , '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>'
                    , '<td><div class="layui-progress" lay-filter="progress-demo-' + index + '"><div class="layui-progress-bar" lay-percent=""></div></div></td>'
                    , '<td>'
                    , '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
                    , '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                    , '</td>'
                    , '</tr>'].join(''));

                //单个重传
                tr.find('.demo-reload').on('click', function () {
                    obj.upload(index, file);
                });

                //删除
                tr.find('.demo-delete').on('click', function () {
                    delete files[index]; //删除对应的文件
                    tr.remove();

                    var tags = [];
                    $(".xuexinname").each(function (i, e) {

                        tags[i] = $(this).val();


                    })

                    $("#fileUrl").val(tags.toString());

                    uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                });

                that.elemList.append(tr);
                element.render('progress'); //渲染新加的进度条组件
            });
        }
        , done: function (res, index, upload) { //成功的回调

            console.log("成功啦");
            var that = this;
            //if(res.code == 0){ //上传成功
            var tr = that.elemList.find('tr#upload-' + index)
                , tds = tr.children();
            //tds.eq(3).html('');

            var tags = [];
            $(".xuexinname").each(function (i, e) {

                tags[i] = $(this).val();


            })

            $("#fileUrl").val(tags.toString());


            //document.getElementById('healthfile').value = ;
            //清空操作
            delete this.files[index]; //删除文件队列已经上传成功的文件
            return;
            //}
            this.error(index, upload);
        }
        , allDone: function (obj) { //多文件上传完毕后的状态回调
            console.log(obj);
            console.log($("#fileUrl").val());
            insertintoxueliFiles($("#fileUrl").val(), $("#jbxxid").val());
            //insertintoFiles($("#healthfile").val(), $("#jbxxid").val());

            table.reload('educationfiles', {

                where: {

                    "Jbxxid": $("#jbxxid").val()


                }

            });


        }
        , error: function (index, upload) { //错误回调
            console.log("错啦~");
            var that = this;
            var tr = that.elemList.find('tr#upload-' + index)
                , tds = tr.children();
            tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传

            var tags = [];
            $(".xuexinname").each(function (i, e) {

                tags[i] = $(this).val();


            })

            $("#fileUrl").val(tags.toString());


        }
        , progress: function (n, elem, e, index) { //注意：index 参数为 layui 2.6.6 新增
            element.progress('progress-demo-' + index, n + '%'); //执行进度条。n 即为返回的进度百分比
        }
    });    





})


function uploadthekrankenstatus(id) {


    if ($("#jbxxid").val() == "") {
        layer.msg("请先填写了基本信息了多");
        return;
    }

    //var _uuid = 'b563f922-fb4e-49a5-a12e-077b8499ef9b';

    var _uuid = $("#jbxxid").val();
    var a = $("#testtedalis").serialize();
    var b = a + '&id=' + id;
    var x = b + '&uuid=' + _uuid;
    
    
    console.log("----------------");
    console.log(x);
    console.log("----------------");


    //console.log(shijian);
    //console.log(jibingshi);
    //console.log(xianzhuang);

    $.ajax({
        url: "/Infos/puttheDiesesinfo",
        type: "post",
        async: false,
        data: x,
        success: function (datas) {



            lis = datas;
            console.log(lis);

            layui.use('layer', function () {
                layer = layui.layer;
                layer.msg('该数据完成提交', { icon: 1 }
                );
            });





        }
    })






}


function uploadtheeducationsinfo(id) {



    if ($("#jbxxid").val() == "") {
        layer.msg("请先填写了基本信息了多");
        return;
    }
    var _uuid = $("#jbxxid").val();
    var a = $("#jiaoyutable").serialize();
    var b = a + '&id=' + id;
    var x = b + '&uuid=' + _uuid;


    $.ajax({
        url: "/Infos/puttheEducationsinfo",
        type: "post",
        async: false,
        data: x,
        success: function (datas) {



            lis = datas;
            console.log(lis);

            layui.use('layer', function () {
                layer = layui.layer;
                layer.msg('该数据完成提交', { icon: 1 }
                );
            });





        }
    })


}
function uploadtheworkinfos(id) {

    if ($("#jbxxid").val() == "") {
        layer.msg("请先填写了基本信息了多");
        return;
    }
    var _uuid = $("#jbxxid").val();
    var a = $("#gongzuotable").serialize();
    var b = a + '&id=' + id;
    var x = b + '&uuid=' + _uuid;


    $.ajax({
        url: "/Infos/puttheworkinfo",
        type: "post",
        async: false,
        data: x,
        success: function (datas) {



            lis = datas;
            console.log(lis);

            layui.use('layer', function () {
                layer = layui.layer;
                layer.msg('该数据完成提交', { icon: 1 }
                );
            });





        }
    })



}



function uploadthefamilysinfos(id) {
    if ($("#jbxxid").val() == "") {
        layer.msg("请先填写了基本信息了多");
        return;
    }



    var _uuid = $("#jbxxid").val();
    var a = $("#family").serialize();
    var b = a + '&id=' + id;
    var x = b + '&uuid=' + _uuid;


    $.ajax({
        url: "/Infos/putthefamilyinfo",
        type: "post",
        async: false,
        data: x,
        success: function (datas) {



            lis = datas;
            console.log(lis);

            layui.use('layer', function () {
                layer = layui.layer;
                layer.msg('该数据完成提交', { icon: 1 }
                );
            });





        }
    })






}

function uploadthejiangchengsinfo(id) {
    if ($("#jbxxid").val() == "") {
        layer.msg("请先填写了基本信息了多");
        return;
    }
    var _uuid = $("#jbxxid").val();
    var a = $("#jiangchengform").serialize();
    var b = a + '&id=' + id;
    var x = b + '&uuid=' + _uuid;

    $.ajax({
        url: "/Infos/putthejcinfo",
        type: "post",
        async: false,
        data: x,
        success: function (datas) {



            lis = datas;
            console.log(lis);

            layui.use('layer', function () {
                layer = layui.layer;
                layer.msg('该数据完成提交', { icon: 1 }
                );
            });





        }
    })








}

function insertintoxueliFiles(string, uuid) {

    if ($("#jbxxid").val() == "") {
        layer.msg("请先填写了基本信息了多");
        return;
    }



    var x = string;
    $.ajax({
        url: "/Infos/_Putthehealthfiles",
        type: "post",
        async: false,
        data: { "cpFile": x, "uuid": uuid },
        /*       data: {"s": x,"uuid":uuid},*/
        success: function (datas) {

            console.log("成功上传啦");
            //$("#gangweisave").attr("disabled", true);
            //document.getElementById("gangweisave").innerHTML = "已经完成保存，请勿重复提交";
            //lis = datas;
            //console.log(lis);
            //globalparams = datas;
            layui.use('layer', function () {
                layer = layui.layer;
                layer.msg('该文件完成上传', { icon: 1 }
                );
            });





        }
    })




}

function proofPicturefileurl(d) {
        var i, count = 0;
        var str = [], aaa = [];
    var proofPicture = d.fileUrl;
        if ('' == proofPicture || null == proofPicture || undefined == proofPicture) {
            return '';
        }
        if (proofPicture.length > 0) {
            str = d.fileUrl.split(",");
            for (i = 0; i < d.fileUrl.length; i++) {
                if (d.fileUrl[i] == ",") { count += 1; }
            }
            for (j = 0; j < count + 1; j++) {
                aaa += '<a class="layui-blue" href="../UploadFiles/' + str[j] + '" target="_blank">' + str[j] + '</a><br/>';
            }

            return aaa;
        }
}

function hegedeni() {

}